package com.dengdai.applibrary.view.custom;

import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dengdai.applibrary.R;
import com.dengdai.applibrary.base.BaseApplication;

/**
 * @说明 头部控件
 * @作者 LY
 * @时间 15/12/15 13:52
 * @版权 Copyright(c) 2015 LY-版权所有
 */
public class TitleBarView {
    private Window window;

    private ImageView iv_left_back;
    private LinearLayout ll_right_btn;
    private TextView tv_right_btn;
    private ImageButton ib_right_btn;
    private TextView tv_title;
    private ImageView iv_title;

    private LinearLayout title_status_bar;


    public TitleBarView(Window window) {
        this.window = window;
    }


    /**
     * 获取左侧控件
     *
     * @return
     */
    public ImageView getLeftBack() {
        if (window != null && iv_left_back == null) {
            iv_left_back = (ImageView) window.findViewById(R.id.iv_left_back);
        }
        return iv_left_back;
    }

    /**
     * 设置左侧按钮
     *
     * @param resId 图片
     */
    public void setLeftBack(int resId) {
        setLeftBack(resId, null);
    }

    /**
     * 设置左侧按钮
     *
     * @param resId         图片资源
     * @param clickListener 事件
     */
    public void setLeftBack(int resId, View.OnClickListener clickListener) {
        getLeftBack().setVisibility(View.VISIBLE);
        getLeftBack().setImageResource(resId);
        getLeftBack().setOnClickListener(clickListener);
    }

    /**
     * 获取标题
     *
     * @return 标题控件
     */
    public TextView getTitle() {
        if (tv_title == null && window != null) {
            tv_title = (TextView) window.findViewById(R.id.tv_title);
        }
        return tv_title;
    }


    /**
     * 设置标题
     *
     * @param resId 标题
     */
    public void setTitle(int resId) {
        setTitle(BaseApplication.getAppContext().getResources().getString(resId));
    }

    /**
     * 设置标题
     *
     * @param title 标题
     */
    public void setTitle(String title) {
        getTitle().setVisibility(View.VISIBLE);
        getTitle().setText(title);
    }

    /**
     * 获取图片标题
     *
     * @return 图片标题控件
     */
    public ImageView getImgTitle() {
        if (window != null && iv_title == null) {
            iv_title = (ImageView) window.findViewById(R.id.iv_title);
        }
        return iv_title;
    }


    /**
     * 设置标题图片
     *
     * @param resID 标题图片
     */
    public void setImgTitle(int resID) {
        getImgTitle().setVisibility(View.VISIBLE);
        getImgTitle().setImageResource(resID);
    }


    public LinearLayout getTitleStatusBar() {
        if (window != null && title_status_bar == null) {
            title_status_bar = (LinearLayout) window.findViewById(R.id.title_status_bar);
        }
        return title_status_bar;
    }

}
